class Solution:
    def getSkyline(self, buildings):
        # 清理无用数据
        xset = set()
        for i in buildings:
            xset.add(i[0])
            xset.add(i[1])
        xlist = list(xset)
        xlist.sort()
        dic = {xlist[i]: [i, 0, 0] for i in range(len(xlist))}

        for one in buildings:
            li = dic[one[0]][0]
            ri = dic[one[1]][0]
            for k in range(li, ri + 1):
                if k != ri:
                    dic[xlist[k]][2] = max(dic[xlist[k]][2], one[2])
                if k != li:
                    dic[xlist[k]][1] = max(dic[xlist[k]][1], one[2])
        result = []
        for i in range(len(xlist)):
            x = dic[xlist[i]]
            if x[1] == x[2]:
                continue
            result.append([xlist[i], x[2]])
        return result


if __name__ == '__main__':
    so = Solution()
    # nums = [[2, 9, 10], [3, 7, 15], [5, 12, 12], [15, 20, 10], [19, 24, 8]]
    nums = [[2,9,10],[9,12,15]]
    r = so.getSkyline(nums)
    print(r)
